const path = require('path');
const {CleanWebpackPlugin} = require("clean-webpack-plugin")
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const webpack = require("webpack");
module.exports = {
    entry: "./src/ohter.js",
    output: {
        path: path.resolve(__dirname, "./dist"),
        filename: "[name].js",
    },
    mode: "development",
    devServer: {
        // hot: true,
        open: true,
        port: 8080,
    },
    devtool: "inline-source-map",
    plugins: [
        new CleanWebpackPlugin(),
        new HtmlWebpackPlugin({
            template: "./src/index.html",
            filename: "index.html",
            title: "Webpack App"
        }),
        // new MiniCssExtractPlugin({
        //     filename: "assets/[name].css",
        // }),
        new webpack.HotModuleReplacementPlugin()
    ],
    resolve: {
        modules: [path.resolve(__dirname, "./node_modules")],
        alias: {
            "@": path.resolve(__dirname, "src"),
        }
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                include: path.resolve(__dirname, "./src"),
                use: ["style-loader", "css-loader"]
            },
            {
                test: /\.less$/,
                include: path.resolve(__dirname, "./src"),
                use: ["style-loader", "css-loader",
                    {
                        loader: "postcss-loader",
                    },
                    {
                        loader: "less-loader",
                    }],
            },
            {
                test: /\.jpg$/,
                include: path.resolve(__dirname, "./src"),
                use: [
                    {
                        loader: "url-loader",
                        options: {
                            name: "[name]_[hash:6].[ext]",
                            outputPath: "image/",
                            limit: 100 * 1024
                        },
                    }
                ]
            },
            {
                test: /\.js$/,
                include: path.resolve(__dirname, "./src"),
                use: {
                    loader: "babel-loader",
                }
            }

        ]
    }
}